package com.bjsxt.func;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;

public class TestFunctionalInterface {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list,10,30,50,20,70,60,40,30,100);
        System.out.println(list.toString());

       //方法1：使用匿名内部类
        Consumer consumer = new Consumer<Integer>() {
            @Override
            public void accept(Integer elem) {
                System.out.println(elem);
            }
        };

        list.forEach(consumer);
        //lambda表达式
        //list.forEach();

        //方法2：使用lambda表达式
        //list.forEach((elem)->{ System.out.println(elem*1.1);});
        list.forEach(elem->System.out.println(elem*1.1));
    }
}
